#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N = 1e5 + 10;
int a[N], f[N], c[N][10], lst[10], sum[N][10];
signed main() {
	freopen("paint.in", "r", stdin);
	freopen("paint.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, m, Q;
	cin >> n >> m >> Q;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			cin >> c[i][j];
			sum[i][j] = sum[i - 1][j] + c[i][j];
		}
	}
	for(int i = 1; i <= m; i++) lst[i] = -1e18;
	for(int i = 1; i <= n; i++) {
		f[i] = f[i - 1] + c[i][a[i]];
		if(lst[a[i]] != -1e18) f[i] = max(f[i], lst[a[i]] + sum[i][a[i]]);
		lst[a[i]] = max(lst[a[i]], f[i - 1] - sum[i - 1][a[i]]);
	}
	cout << f[n] << '\n';
	int pre = f[n];
	int num = 0;
	while(Q--) {
		int op, p, q;
		cin >> op >> p >> q;
		p ^= pre;
		q ^= pre;
		if(op == 1) a[p] = q;
		else {
			f[p - 1] = 0;
			for(int i = 1; i <= m; i++) lst[i] = -1e18;
			for(int i = p; i <= q; i++) {
				++num;
				f[i] = f[i - 1] + c[i][a[i]];
				if(lst[a[i]] != -1e18) f[i] = max(f[i], lst[a[i]] + sum[i][a[i]]);
				lst[a[i]] = max(lst[a[i]], f[i - 1] - sum[i - 1][a[i]]);
			}
			cout << f[q] << '\n';
			pre = f[q];
		}
	}
	return 0;
}

